import { defineAsyncComponent } from "vue";

const modules = import.meta.glob("./*.vue");
const myComponents = {};
for (const path in modules) {
  // await modules[path]();
  const componentName = path.replace(/^\.\/(.*)\.vue$/, "$1");
  myComponents[componentName] = defineAsyncComponent(modules[path]); // 直接使用meta.glob加载的组件即可
}

const myPlugin = {
  install(app, options) {
    // 有了 app，我们注入一个全局组件
    for (const key in myComponents) {
      app.component(key, myComponents[key]);
    }
  },
};

export default myPlugin;
